package chuangyi.com.org.DOMIHome;

import android.app.Activity;

/**
 * Created by zxh on 16/12/22.
 */


import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;
import android.widget.TextView;

import java.util.List;

import chuangyi.com.org.ViewModel.DaoMaster;
import chuangyi.com.org.ViewModel.User;


public class splashscreen extends Activity {
    /**
     * Called when the activity is first created.
     */

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        getWindow().setFormat(PixelFormat.RGBA_8888);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);

        setContentView(R.layout.splash_screen);

//        //Display the current version number
//        PackageManager pm = getPackageManager();
//        try {
//            PackageInfo pi = pm.getPackageInfo("org.wordpress.android", 0);
//            TextView versionNumber = (TextView) findViewById(R.id.versionNumber);
//            versionNumber.setText("Version " + pi.versionName);
//        } catch (NameNotFoundException e) {
//            e.printStackTrace();
//        }

        new Handler().postDelayed(new Runnable() {
            public void run() {
                /* Create an Intent that will start the Main WordPress Activity. */
                Intent mainIntent = null;
                List<User> list = DBManager.getInstance(splashscreen.this.getApplicationContext())
                        .queryUserList();
                if (list != null && list.size() > 0) {
                    User.setCurrentUser(list.get(0));
                    mainIntent = new Intent(splashscreen.this, HomeActivity.class);
                } else {
                    mainIntent = new Intent(splashscreen.this, LoginActivity.class);
                }
                splashscreen.this.startActivity(mainIntent);
                splashscreen.this.finish();
            }
        }, 2900); //2900 for release

    }
}
